home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT47.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  3.5 KB  |  89 lines

  1. /*
  2. ==============================================================================
  3.                       WordUp Graphics Toolkit Version 5.0                     
  4.                              Demonstration Program 47                         
  5.                                                                               
  6.   Demonstrates the use of the wfilesel routine. It will draw some random      
  7.   images on the screen and then call the file selector which will appear      
  8.   superimposed on the screen. The user may select a BLK file to be loaded     
  9.   and displayed.                                                              
  10.                                                                               
  11.   *** PROJECT ***                                                             
  12.   This program requires the WGT5_WC.LIB and WFILE_WC.LIB files to be linked.  
  13.                                                                               
  14.   *** DATA FILES ***                                                          
  15.   LITTLE.WFN must be in the executable directory.                             
  16.                                                            WATCOM C++ VERSION 
  17. ==============================================================================
  18. */
  19.  
  20. #include <stdlib.h>
  21. #include <conio.h>
  22. #include <wgt5.h>
  23.  
  24.  
  25. void main (void)
  26. {
  27.   block screenbuf;
  28.   color pal[256];
  29.   char *filename;
  30.   short oldmode;
  31.   wgtfont little;
  32.   short ctr;
  33.  
  34.   if ( !vgadetected () )
  35.   {
  36.     printf ("Error - VGA card required for any WGT program.\n");
  37.     exit (0);
  38.   }
  39.  
  40.   printf ("WGT Example #47\n\n");
  41.   printf ("The file selector is used to select and load a block file.\n");
  42.   printf ("\n\nPress any key to continue.\n");
  43.   getch ();
  44.  
  45.   oldmode = wgetmode ();         /* Store current video mode     */
  46.   vga256 ();                     /* Initialize WGT system        */
  47.  
  48.   for (ctr = 0; ctr < 100; ctr++)             /* Create a random screen */
  49.   {
  50.     wsetcolor (rand () % 256);
  51.     wline (rand () % 320, rand () % 200, rand () % 320, rand () % 200);
  52.   }
  53.     
  54.   screenbuf = wnewblock (0, 0, 319, 199);       /* Preserve the screen */
  55.  
  56.   minit ();                                     /* Mouse must be on */
  57.  
  58.   wreadpalette (0, 255, pal);                   /* Store current palette */
  59.  
  60.   /* The file selector uses color indices 253-255, so you must set these
  61.      to represent the colors you'd like */
  62.   wsetrgb (253, 63, 63, 63, pal);         /* White */
  63.   wsetrgb (254, 40, 40, 40, pal);         /* Light Gray */
  64.   wsetrgb (255, 30, 30, 30, pal);         /* Dark Gray */
  65.   wsetpalette (253, 255, pal);            /* Set the colors */
  66.  
  67.   little = wloadfont ("little.wfn");    /* Load our font for selector */
  68.   filefont = little;                    /* Set the font variable */
  69.  
  70.   /* Now open a moveable file selector which will prompt for BLK files */
  71.   filename = wfilesel ("BLK", "Load Block File", 40, 10, screenbuf);
  72.   moff ();
  73.   mdeinit ();
  74.  
  75.   wfreefont (little);               /* Deallocate the font */
  76.   wfreeblock (screenbuf);           /* Free the screen buffer */
  77.   if (filename != NULL)             /* Did the user select a file? */
  78.   {
  79.     screenbuf = wloadblock (filename);          /* Load the image */
  80.     if (screenbuf != NULL)
  81.     {
  82.       wputblock (0, 0, screenbuf, NORMAL);      /* Display it */
  83.       wfreeblock (screenbuf);                   /* Free the memory */
  84.       getch ();                                 /* Wait for a keypress */
  85.     }
  86.   }
  87.   wsetmode (oldmode);
  88. }
  89.